<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link href="/css/common.css" rel="stylesheet" type="text/css" />
<style>
.wrapContent {margin:0 auto;padding:0 30px;}
.center {text-align:center;}
.block {padding:10px 30px;}
.line {border:none;border-bottom:1px solid #666;clear:both;}
.orderSN {float:left;}
.orderMan {float:right;margin:-6px 20px 0 0;}
ul.machineType{width:80%;}
ul.machineType li{float:left;width:33%;line-height:26px;height:26px;}
.lineHeight{height:34px;line-height:34px;}
.right {text-align:right;width:120px;vertical-align:top}
.errMsg {color:red;margin:0 0 0 5px;}
</style>
</head>
<body>
<div class="wrapContent">
	<div class="block">
		<h2 class="center">修改库存</h2>
		<table style="width:50%;border:none;margin:0 auto;" cellpadding="0" cellspacing="0">
			<tr class="lineHeight">
				<td class="right">硒鼓类型：</td>
				<td><?php echo $info['type'] ?></td>
			</tr>
			<?php
				foreach($warehouse as $id=>$name){
			?>
			<tr class="lineHeight">
				<td class="right"><?php echo $name; ?>：</td>
				<td><input id="<?php echo $id; ?>" value="<?php echo $info['inventory'][$id] ?>" size="6" maxLength="6" style="width:50px;"/><b id="<?php echo $id; ?>ErrMsg" class="errMsg">*</b></td>
			</tr>
			<?php } ?>
		</table>
	</div>
	<div class="center">
		<input id="submit" type="button" class="submitBtn" value="修改"/>
	</div>
</div>
</body>
<script src="/js/lib.min.js" type="text/javascript"></script>
<script type="text/javascript">
<?php echo "var ids=" . json_encode(array_keys($warehouse)) . ";\n";?>
var submitBtn = $('#submit');
submitBtn.attr({onclick:function(){
	var data={}, checkFlag = true;
	data['type_id'] = '<?php echo $info['id']; ?>';
	for(var i=0,id; id=ids[i++];){
		data[id] = $.trim($('#'+id).val());
		if ((data[id]|0) != data[id]) {
			$('#'+id+'ErrMsg').html('请正确输入库存数量');
			checkFlag = false;
		}
	}
	if (!checkFlag)return ;
	
	submitBtn.val('正在处理，请稍后...');
	submitBtn[0].disabled = true;
	
	$.ajax({
		'url':'/admin/inventory.php?op=doModify',
		'data':data,
		'type':'POST',
		'callback':function(res){
			alert(res.errmsg);
			submitBtn.val('修改');
			submitBtn[0].disabled = true;
			if (res.errno == '0') {
				location.href = '/admin/inventory.php?op=query';
			}
		}
	});	
}});
</script>
</html>